﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace WinCSharp
{
    public partial class RegexForm : Form
    {
        public RegexForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 替换.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReplace_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<tr A>");
            sb.AppendLine("<tr B>");
            sb.AppendLine("<tr C>");
            sb.AppendLine("<tr D>");
            sb.AppendLine("<tr E>");

            //将所有的括号中的项目指定为:$1,$2,$3,$4,$5, 然后替换为XX
            string result = Regex.Replace(sb.ToString(), @"(<tr )([A-Z])(>)", "$1中国$3");
            richTextBox1.Text = result;
        }
    }
}
